<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="laravel-的-facades" tabindex="-1"><a class="header-anchor" href="#laravel-的-facades"><span>Laravel 的 Facades</span></a></h2>
<ul>
<li><a href="#introduction">简介</a></li>
<li><a href="#when-to-use-facades">何时使用 Facades</a>
<ul>
<li><a href="#facades-vs-dependency-injection">Facades Vs. 依赖注入</a></li>
<li><a href="#facades-vs-helper-functions">Facades Vs. 辅助函数</a></li>
</ul>
</li>
<li><a href="#how-facades-work">Facades 工作原理</a></li>
<li><a href="#facade-class-reference">Facade 类参考</a></li>
</ul>
<h2 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h2>
<p>Facades（读音：/fəˈsäd/ ）为应用程序的 <a href="https://learnku.com/docs/laravel/5.5/container" target="_blank" rel="noopener noreferrer">服务容器</a> 中可用的类提供了一个「静态」接口。Laravel 自带了很多 Facades ，可以访问绝大部分 Laravel 的功能。Laravel Facades 实际上是服务容器中底层类的「静态代理」，它提供了简洁而富有表现力的语法，甚至比传统的静态方法更具可测试性和扩展性。</p>
<p>所有的 Laravel Facades 都在 <code v-pre>Illuminate\Support\Facades</code> 命名空间中定义。所以，我们可以轻松地使用 Facade :</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Route</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/cache'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token class-name static-context">Cache</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'key'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在 Laravel 的文档中，很多示例代码都会使用 Facades 来演示框架的各种功能。</p>
<h2 id="何时使用-facades" tabindex="-1"><a class="header-anchor" href="#何时使用-facades"><span>何时使用 Facades</span></a></h2>
<p>Facades 有很多好处，它为我们使用 Laravel 的功能提供了简单、易记的语法，而无需记住必须手动注入或配置的长长的类名。此外，由于它们对 PHP 动态方法的独特用法，使得测试起来非常容易。</p>
<p>然而，在使用 Facades 时，有些地方还需要特别注意。使用 Facades 最主要的风险就是会引起类作用范围的膨胀。因为 Facades 使用起来非常简单而且不需要注入，就会使得我们在不经意间在单个类中使用许多 Facades，从而导致类变的越来越大。而使用依赖注入的时候，使用的类越多，构造方法就会越长，在视觉上就会引起注意，提醒你这个类有点庞大了。因此在使用 Facades 的时候，要特别注意控制好类的大小，让类的作用范围保持短小。</p>
<blockquote>
<p>{tip} 在开发与 Laravel 进行交互的第三方扩展包时，建议最好选择注入 <a href="https://learnku.com/docs/laravel/5.5/contracts" target="_blank" rel="noopener noreferrer">Laravel 契约</a> ，而不是使用 Facades 的方式来使用类。因为扩展包是在 Laravel 本身之外构建，所以你无法使用 Laravel Facades 测试辅助函数。</p>
</blockquote>
<h3 id="facades-vs-依赖注入" tabindex="-1"><a class="header-anchor" href="#facades-vs-依赖注入"><span>Facades Vs. 依赖注入</span></a></h3>
<p>依赖注入的主要优点之一是切换注入类的实现的能力。这在测试的时候很有用，因为你可以注入一个 mock 或者 stub ，并断言在 stub 上调用的各种方法。</p>
<p>通常，真正的静态方法是不可能被 mock 或者 stub。但是，因为 Facades 使用动态方法来代理从服务容器解析的对象的方法调用，我们可以像测试注入的类实例一样来测试 Facades。例如，像下面的路由：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Route</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/cache'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token class-name static-context">Cache</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'key'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>我们可以用下面的测试代码来验证使用预期的参数来调用 <code v-pre>Cache::get</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 一个基础功能的测试用例。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">testBasicExample</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">Cache</span><span class="token operator">::</span><span class="token function">shouldReceive</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'get'</span><span class="token punctuation">)</span></span>
<span class="line">         <span class="token operator">-></span><span class="token function">with</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'key'</span><span class="token punctuation">)</span></span>
<span class="line">         <span class="token operator">-></span><span class="token function">andReturn</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">visit</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/cache'</span><span class="token punctuation">)</span></span>
<span class="line">         <span class="token operator">-></span><span class="token function">see</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="facades-vs-辅助函数" tabindex="-1"><a class="header-anchor" href="#facades-vs-辅助函数"><span>Facades Vs. 辅助函数</span></a></h3>
<p>除了 Facades， Laravel 还包含各种「辅助函数」来实现一些常用的功能，比如生成视图、触发事件、调度任务或者发送 HTTP 响应。许多辅助函数的功能都有与之对应的 Facade。例如，下面这个 Facade 的调用和辅助函数的作用是一样的：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token class-name static-context">View</span><span class="token operator">::</span><span class="token function">make</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'profile'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">return</span> <span class="token function">view</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'profile'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>这里的 Facades 和辅助函数之间没有实际的区别。当你使用辅助函数时，你可以使用对应的 Facade 进行测试。例如，下面的路由：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Route</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/cache'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token function">cache</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'key'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在底层，辅助函数 <code v-pre>cache</code> 实际是调用 <code v-pre>Cache</code> facade 中的 <code v-pre>get</code> 方法。因此，尽管我们使用的是辅助函数，我们依然可以编写以下测试来验证该方法是否使用我们预期的参数来调用：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 一个基础功能的测试用例。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">testBasicExample</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">Cache</span><span class="token operator">::</span><span class="token function">shouldReceive</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'get'</span><span class="token punctuation">)</span></span>
<span class="line">         <span class="token operator">-></span><span class="token function">with</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'key'</span><span class="token punctuation">)</span></span>
<span class="line">         <span class="token operator">-></span><span class="token function">andReturn</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">visit</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'/cache'</span><span class="token punctuation">)</span></span>
<span class="line">         <span class="token operator">-></span><span class="token function">see</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'value'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="facades-工作原理" tabindex="-1"><a class="header-anchor" href="#facades-工作原理"><span>Facades 工作原理</span></a></h2>
<p>在 Laravel 应用中，Facade 就是一个可以从容器访问对象的类。其中核心的部件就是 <code v-pre>Facade</code> 类。不管是 Laravel 自带的 Facades，还是用户自定义的 Facades ，都继承自 <code v-pre>Illuminate\Support\Facades\Facade</code> 类。</p>
<p><code v-pre>Facade</code> 基类使用了 <code v-pre>__callStatic()</code> 魔术方法将你的 Facades 的调用延迟，直到对象从容器中被解析出来。在下面的例子中，调用了 Laravel 的缓存系统。通过浏览这段代码，可以假定在 <code v-pre>Cache</code> 类中调用了静态方法 <code v-pre>get</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Cache</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers<span class="token punctuation">\</span>Controller</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">UserController</span> <span class="token keyword">extends</span> <span class="token class-name">Controller</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 显示给定用户的信息。</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">int</span></span>  <span class="token parameter">$id</span></span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name">Response</span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">showProfile</span><span class="token punctuation">(</span><span class="token variable">$id</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$user</span> <span class="token operator">=</span> <span class="token class-name static-context">Cache</span><span class="token operator">::</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'user:'</span><span class="token operator">.</span><span class="token variable">$id</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token function">view</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'profile'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'user'</span> <span class="token operator">=></span> <span class="token variable">$user</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>注意在上面这段代码中，我们「导入」<code v-pre>Cache</code> Facade 。这个 Facade 作为访问 <code v-pre>Illuminate\Contracts\Cache\Factory</code> 接口底层实现的代理。我们使用 Facade 进行的任何调用都将传递给 Laravel 缓存服务的底层实例。</p>
<p>如果我们看一下 <code v-pre>Illuminate\Support\Facades\Cache</code> 这个类，你会发现类中根本没有 <code v-pre>get</code> 这个静态方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">Cache</span> <span class="token keyword">extends</span> <span class="token class-name">Facade</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 获取组件的注册名称。</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">string</span></span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token keyword">static</span> <span class="token keyword">function</span> <span class="token function-definition function">getFacadeAccessor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token string single-quoted-string">'cache'</span><span class="token punctuation">;</span> <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><code v-pre>Cache</code> Facade 继承了 <code v-pre>Facade</code> 的类库，并且定义了 <code v-pre>getFacadeAccessor()</code> 方法。这个方法的作用是返回服务容器绑定的名称。当用户调用 <code v-pre>Cache</code> Facade 中的任何静态方法时， Laravel 会从 <a href="https://learnku.com/docs/laravel/5.5/container" target="_blank" rel="noopener noreferrer">服务容器</a> 中解析 <code v-pre>cache</code> 绑定以及该对象运行所请求的方法（在这个例子中就是 <code v-pre>get</code> 方法）。</p>
<h2 id="facade-类参考" tabindex="-1"><a class="header-anchor" href="#facade-类参考"><span>Facade 类参考</span></a></h2>
<p>在下面你可以找到每个 Facade 类及其对应的底层类。这是一个查找给定 Facade 类 API 文档的工具。<a href="https://learnku.com/docs/laravel/5.5/container" target="_blank" rel="noopener noreferrer">服务容器绑定</a> 的可用键值也包含在内。</p>
<table>
<thead>
<tr>
<th>Facade</th>
<th>类</th>
<th>服务容器绑定</th>
</tr>
</thead>
<tbody>
<tr>
<td>App</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Foundation/Application.html" target="_blank" rel="noopener noreferrer">Illuminate\Foundation\Application</a></td>
<td><code v-pre>app</code></td>
</tr>
<tr>
<td>Artisan</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Contracts/Console/Kernel.html" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Console\Kernel</a></td>
<td><code v-pre>artisan</code></td>
</tr>
<tr>
<td>Auth</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Auth/AuthManager.html" target="_blank" rel="noopener noreferrer">Illuminate\Auth\AuthManager</a></td>
<td><code v-pre>auth</code></td>
</tr>
<tr>
<td>Blade</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/View/Compilers/BladeCompiler.html" target="_blank" rel="noopener noreferrer">Illuminate\View\Compilers\BladeCompiler</a></td>
<td><code v-pre>blade.compiler</code></td>
</tr>
<tr>
<td>Bus</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Contracts/Bus/Dispatcher.html" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Bus\Dispatcher</a></td>
<td></td>
</tr>
<tr>
<td>Cache</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Cache/Repository.html" target="_blank" rel="noopener noreferrer">Illuminate\Cache\Repository</a></td>
<td><code v-pre>cache</code></td>
</tr>
<tr>
<td>Config</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Config/Repository.html" target="_blank" rel="noopener noreferrer">Illuminate\Config\Repository</a></td>
<td><code v-pre>config</code></td>
</tr>
<tr>
<td>Cookie</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Cookie/CookieJar.html" target="_blank" rel="noopener noreferrer">Illuminate\Cookie\CookieJar</a></td>
<td><code v-pre>cookie</code></td>
</tr>
<tr>
<td>Crypt</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Encryption/Encrypter.html" target="_blank" rel="noopener noreferrer">Illuminate\Encryption\Encrypter</a></td>
<td><code v-pre>encrypter</code></td>
</tr>
<tr>
<td>DB</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Database/DatabaseManager.html" target="_blank" rel="noopener noreferrer">Illuminate\Database\DatabaseManager</a></td>
<td><code v-pre>db</code></td>
</tr>
<tr>
<td>DB (Instance)</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Database/Connection.html" target="_blank" rel="noopener noreferrer">Illuminate\Database\Connection</a></td>
<td></td>
</tr>
<tr>
<td>Event</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Events/Dispatcher.html" target="_blank" rel="noopener noreferrer">Illuminate\Events\Dispatcher</a></td>
<td><code v-pre>events</code></td>
</tr>
<tr>
<td>File</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Filesystem/Filesystem.html" target="_blank" rel="noopener noreferrer">Illuminate\Filesystem\Filesystem</a></td>
<td><code v-pre>files</code></td>
</tr>
<tr>
<td>Gate</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Contracts/Auth/Access/Gate.html" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\Access\Gate</a></td>
<td></td>
</tr>
<tr>
<td>Hash</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Contracts/Hashing/Hasher.html" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Hashing\Hasher</a></td>
<td><code v-pre>hash</code></td>
</tr>
<tr>
<td>Lang</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Translation/Translator.html" target="_blank" rel="noopener noreferrer">Illuminate\Translation\Translator</a></td>
<td><code v-pre>translator</code></td>
</tr>
<tr>
<td>Log</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Log/Writer.html" target="_blank" rel="noopener noreferrer">Illuminate\Log\Writer</a></td>
<td><code v-pre>log</code></td>
</tr>
<tr>
<td>Mail</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Mail/Mailer.html" target="_blank" rel="noopener noreferrer">Illuminate\Mail\Mailer</a></td>
<td><code v-pre>mailer</code></td>
</tr>
<tr>
<td>Notification</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Notifications/ChannelManager.html" target="_blank" rel="noopener noreferrer">Illuminate\Notifications\ChannelManager</a></td>
<td></td>
</tr>
<tr>
<td>Password</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Auth/Passwords/PasswordBrokerManager.html" target="_blank" rel="noopener noreferrer">Illuminate\Auth\Passwords\PasswordBrokerMa...</a></td>
<td><code v-pre>auth.password</code></td>
</tr>
<tr>
<td>Queue</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Queue/QueueManager.html" target="_blank" rel="noopener noreferrer">Illuminate\Queue\QueueManager</a></td>
<td><code v-pre>queue</code></td>
</tr>
<tr>
<td>Queue (Instance)</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Contracts/Queue/Queue.html" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\Queue</a></td>
<td><code v-pre>queue</code></td>
</tr>
<tr>
<td>Queue (Base Class)</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Queue/Queue.html" target="_blank" rel="noopener noreferrer">Illuminate\Queue\Queue</a></td>
<td></td>
</tr>
<tr>
<td>Redirect</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Routing/Redirector.html" target="_blank" rel="noopener noreferrer">Illuminate\Routing\Redirector</a></td>
<td><code v-pre>redirect</code></td>
</tr>
<tr>
<td>Redis</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Redis/Database.html" target="_blank" rel="noopener noreferrer">Illuminate\Redis\Database</a></td>
<td><code v-pre>redis</code></td>
</tr>
<tr>
<td>Request</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Http/Request.html" target="_blank" rel="noopener noreferrer">Illuminate\Http\Request</a></td>
<td><code v-pre>request</code></td>
</tr>
<tr>
<td>Response</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Contracts/Routing/ResponseFactory.html" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Routing\ResponseFacto...</a></td>
<td></td>
</tr>
<tr>
<td>Route</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Routing/Router.html" target="_blank" rel="noopener noreferrer">Illuminate\Routing\Router</a></td>
<td><code v-pre>router</code></td>
</tr>
<tr>
<td>Schema</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Database/Schema/Blueprint.html" target="_blank" rel="noopener noreferrer">Illuminate\Database\Schema\Blueprint</a></td>
<td></td>
</tr>
<tr>
<td>Session</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Session/SessionManager.html" target="_blank" rel="noopener noreferrer">Illuminate\Session\SessionManager</a></td>
<td><code v-pre>session</code></td>
</tr>
<tr>
<td>Session (Instance)</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Session/Store.html" target="_blank" rel="noopener noreferrer">Illuminate\Session\Store</a></td>
<td></td>
</tr>
<tr>
<td>Storage</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Contracts/Filesystem/Factory.html" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Filesystem\Factory</a></td>
<td><code v-pre>filesystem</code></td>
</tr>
<tr>
<td>URL</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Routing/UrlGenerator.html" target="_blank" rel="noopener noreferrer">Illuminate\Routing\UrlGenerator</a></td>
<td><code v-pre>url</code></td>
</tr>
<tr>
<td>Validator</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Validation/Factory.html" target="_blank" rel="noopener noreferrer">Illuminate\Validation\Factory</a></td>
<td><code v-pre>validator</code></td>
</tr>
<tr>
<td>Validator (Instance)</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/Validation/Validator.html" target="_blank" rel="noopener noreferrer">Illuminate\Validation\Validator</a></td>
<td></td>
</tr>
<tr>
<td>View</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/View/Factory.html" target="_blank" rel="noopener noreferrer">Illuminate\View\Factory</a></td>
<td><code v-pre>view</code></td>
</tr>
<tr>
<td>View (Instance)</td>
<td><a href="https://laravel.com/api/5.5/Illuminate/View/View.html" target="_blank" rel="noopener noreferrer">Illuminate\View\View</a></td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="译者署名" tabindex="-1"><a class="header-anchor" href="#译者署名"><span>译者署名</span></a></h2>
<table>
<thead>
<tr>
<th>用户名</th>
<th>头像</th>
<th>职能</th>
<th>签名</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="http://blog.clayidols.com/" target="_blank" rel="noopener noreferrer">@clayidols</a></td>
<td><img src="https://avatars2.githubusercontent.com/u/21217903?v=4&amp;s=460" alt="21217903?v=4&amp;s=460"></td>
<td>Review</td>
<td>痴呆哥哥</td>
</tr>
<tr>
<td><a href="https://learnku.com/users/5350" target="_blank" rel="noopener noreferrer">@JokerLinly</a></td>
<td><img src="https://cdn.learnku.com/uploads/avatars/5350_1481857380.jpg" alt="5350_1481857380.jpg"></td>
<td>Review</td>
<td>Stay Hungry. Stay Foolish.</td>
</tr>
</tbody>
</table>
<hr>
<blockquote>
<p>{note} 欢迎任何形式的转载，但请务必注明出处，尊重他人劳动共创开源社区。</p>
<p>转载请注明：本文档由 Laravel China 社区 <a href="https://laravel-china.org/" target="_blank" rel="noopener noreferrer">laravel-china.org</a> 组织翻译，详见 <a href="https://learnku.com/laravel/t/5756/laravel-55-document-translation-call-come-and-join-the-translation" target="_blank" rel="noopener noreferrer">翻译召集帖</a>。</p>
<p>文档永久地址： <a href="https://learnku.com/docs/laravel" target="_blank" rel="noopener noreferrer">《Laravel 中文文档》</a></p>
</blockquote>
</div></template>


